package lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/**
 * @author ：黄淼淳
 * @description：资源类
 * @date ：2021/12/11 19:54
 */
public class Resource {
    private int number = 100;
    Lock lock = new ReentrantLock();

    public void sale() {
        lock.lock();
        try {
            if (number>0){
                System.out.println(Thread.currentThread().getName()+"卖出第："+number--+"\t 还剩下："+(99-number)+"张票");
            }else {
                Thread.currentThread().interrupt();
            }
        } finally {
            lock.unlock();
        }
    }
}
